﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Hotnet.Entity;
using Hotnet.Dal.BaseRepository;
using Hotnet.Entity.Enum;

namespace Hotnet.Dal.NSDalVideo
{
	public class DalCastCharacter:Repository<CastCharacter>
	{
		private string connectionString = System.Configuration.ConfigurationManager.ConnectionStrings["HotnetConnectionString"].ConnectionString;
		public void Insert(List<CastCharacter> models)
		{
			using (HotnetDBDataContext ctx = new HotnetDBDataContext(connectionString))
			{
				ctx.GetTable<CastCharacter>().InsertAllOnSubmit(models);
				ctx.SubmitChanges();
			}
		}

		/// <summary>
		/// 列出video 的演员castCharacter
		/// </summary>
		/// <param name="id"></param>
		/// <returns></returns>
		public CastCharacter[] ListVideoCastCharacters(int id)
		{
			return ListBy(x => x.VideoID == id );
		}

		/// <summary>
		/// 列出video的演员列表 star
		/// </summary>
		/// <param name="id"></param>
		/// <returns></returns>
		public Star[] ListVideoCastStars(int id)
		{
			var query = from star in disableCacheDataContext.Star
						join castCharacter in disableCacheDataContext.CastCharacter
							on star.StarID equals castCharacter.StarID
							where castCharacter.VideoID==id
						select star;
			return query.ToArray();
		}

		public override void Delete(int id)
		{
			DeleteBy(x => x.VideoID == id);
		}
	}
}
